home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HAM Radio 1997
/
HAM Radio 1997.iso
/
vcls
/
enterctl
/
readme.txt
< prev
Wrap
Text File
|
1996-04-08
|
2KB
|
45 lines
Using the <Enter> key like a <Tab> key with Delphi Controls
===========================================================
The example code supplied here demonstrates how to trap the
<Enter> key and the cursor keys to provide better data entry
processing.
The trick is to overide the Keypress and KeyDown events so
that they process the keys the way you want. In the examples
supplied I have used the <Enter> key to move to the next
control (like the <Tab> key) and the cursor Up and Down keys
to move to the previous and next controls respectively.
The Edit and EBEdit use the cursor keys as stated above, but
the Combobox and the Listbox use Shift-Up and Shift-Down
instead so as not to interfere with existing functionality.
The Grid control uses the <Enter> key to move between fields,
however it will not move from the last field of the last row.
It is very easy to make it exit the grid at this point if you
need to.
The method used to move to the next/previous control is the
Windows API call SendMessage which is used to dispatch a
WM_NEXTDLGCTL to the form the controls are children to.
Delphi provides a function called GetParentForm to get the
handle of the parent form of the control.
These simple extensions can be expanded to respond to almost
any keyboard event, and I think using this method is less
trouble than trapping keys in the forms OnKey events (using
keypreview:=true).
Feel free to use the code as you wish, but if you discover
something new please let me in on it!
Simon Callcott
CIS: 100574,1034